﻿using Microsoft.Extensions.ObjectPool;
using StackExchange.Redis;

namespace Canteen.Core.Common
{
    public class RedisCachePooledObjectPolicy : IPooledObjectPolicy<RedisCache>
    {
        private readonly ConfigurationOptions _options;
        public RedisCachePooledObjectPolicy(ConfigurationOptions options)
        {
            _options = options;
        }

        public RedisCache Create()
        {
            return new RedisCache(_options);
        }

        public bool Return(RedisCache obj)
        {
            if (obj.IsConnecte) return true;
            else return false;
        }
    }
}